package com.chrudgames.stayintouch;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;

public class Help extends Activity  {

	
	/** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {

    	
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.help);
    
    }
	
protected void onStart() {
	
	 super.onStart();
	
	     WebView webview = (WebView) findViewById(R.id.webView);

     //webview.loadUrl("file:///android_asset/help.html"); 
	     webview.loadDataWithBaseURL("", readTextFromResource(R.raw.help), "text/html", "utf-8", "");
	
}    

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.layout.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        
    case R.id.communicate:
    	Intent i4 = new Intent(this, Communicate.class);

    	startActivity(i4);
    	return true;
  	
    case R.id.options:
        	Intent i = new Intent(this, Prefs.class);
           	startActivity(i);
	
            return true;
        case R.id.upgrade:
        	Intent i3 = new Intent(this, Upgrade.class);
           	startActivity(i3);
            return true;
        case R.id.help:
        	Intent i2 = new Intent(this, Help.class);
           	startActivity(i2);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

private String readTextFromResource(int resourceID)
{
	InputStream raw = getResources().openRawResource(resourceID);
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	int i;
	try
	{
		i = raw.read();
		while (i != -1)
		{
			stream.write(i);
			i = raw.read();
		}
		raw.close();
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	return stream.toString();
}
    


}